package com.example.mrzhou.lvmm.view.fragment.surround;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.base.BaseFragment;
import com.example.mrzhou.lvmm.entity.surround.hotel.Hotel;
import com.example.mrzhou.lvmm.presenter.surround.HotelPresenter;
import com.example.mrzhou.lvmm.view.adapter.surround.HotelAdapter;
import com.example.mrzhou.lvmm.view.impl.surround.HotelView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class SurHotelFragment extends BaseFragment implements HotelView {


    @BindView(R.id.rclv_sur_hotel)
    RecyclerView rclvSurHotel;
    private HotelAdapter adapter;
    private List<Hotel.DataBean.HotelListBean> data = new ArrayList<>();

    private static OnSurHotelCallBack callBack;

    public SurHotelFragment() {
        // Required empty public constructor
    }

    public static SurHotelFragment newInstance(OnSurHotelCallBack mcallBack) {

        callBack = mcallBack;

        Bundle args = new Bundle();

        SurHotelFragment fragment = new SurHotelFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_sur_hotel;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this, view);
        rclvSurHotel.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new HotelAdapter(data, getContext());
        rclvSurHotel.setAdapter(adapter);
        initData();
    }

    /**
     * Content-Disposition: form-data; name="latitude"
     * Content-Length: 9
     * <p>
     * 39.913249
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="longitude"
     * Content-Length: 10
     * <p>
     * 116.403625
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="uuid"
     * Content-Length: 36
     * <p>
     * 5726704f-94e7-4a75-8553-2cf5b2645058
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="distance"
     * Content-Length: 2
     * <p>
     * 10
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="hotelStar"
     * Content-Length: 23
     * <p>
     * 104,105,102,103,100,101
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="arrivalDate"
     * Content-Length: 10
     * <p>
     * 2016-10-26
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="departureDate"
     * Content-Length: 10
     * <p>
     * 2016-10-27
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="pageIndex"
     * Content-Length: 1
     * <p>
     * 1
     * --de3dbe55-35e0-468d-914d-d858f7743143
     * Content-Disposition: form-data; name="version"
     * Content-Length: 5
     * <p>
     * 3.0.0
     * --de3dbe55-35e0-468d-914d-d858f7743143--
     */
    @Override
    protected void initData() {
        HotelPresenter presenter = new HotelPresenter(this);
        Map<String, String> map = new HashMap<>();
        map.put("latitude", "39.913249");
        map.put("longitude", "116.403625");
        map.put("uuid", "5726704f-94e7-4a75-8553-2cf5b2645058");
        map.put("distance", "10");
        map.put("hotelStar", "104,105,102,103,100,101");
        map.put("arrivalDate", "2016-10-26");
        map.put("departureDate", "2016-10-27");
        map.put("pageIndex", "1");
        map.put("version", "3.0.0");
        presenter.getHotelData(map);
    }


    @Override
    public void onSuccess(Hotel hotel) {
        if (hotel != null) {
            data.addAll(hotel.getData().getHotelList());
            adapter.notifyDataSetChanged();
            callBack.onSurHotelCallBack(hotel);
        }
    }

    @Override
    public void onFaiure(Throwable a) {

    }

    @Override
    public void onFinsh() {

    }

    public interface OnSurHotelCallBack {
        void onSurHotelCallBack(Hotel hotel);
    }
}
